﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using S.EliminationOrDath.Domain.Enums;
using S.EliminationOrDath.Read.API.Application.Command.SheepDeathCommand;

namespace S.EliminationOrDath.Read.API.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class SheepDeathController : ControllerBase
    {
        private readonly IMediator _mediator;
        public SheepDeathController(IMediator mediator)
        {
            _mediator= mediator;
        }
        /// <summary>
        /// 根据主键Id进行批量查死亡信息
        /// </summary>
        /// <param name="DeathIds"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> GetDeathIds(string? DeathIds)
        {
            SheepDeathIdsCommand command = new SheepDeathIdsCommand();
            command.DeathIds = DeathIds;
            var list=await _mediator.Send(command);
            return Ok(list);
        }
        /// <summary>
        /// 羊只死亡查询+分页
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="sdate"></param>
        /// <param name="edate"></param>
        /// <param name="EarTag"></param>
        /// <param name="DId"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> GetDeathListPage(int pageIndex, int pageSize, string? sdate, string? edate, string? EarTag, int DId)
        {
            SheepDeathListPageCommand command= new SheepDeathListPageCommand();
            command.pageIndex=pageIndex;
            command.pageSize=pageSize;
            command.Sdate=sdate;
            command.edate=edate;
            command.EarTag=EarTag;
            command.DId=DId;
            var list=await _mediator.Send(command);
            return Ok(list);
        }
        /// <summary>
        /// 死亡原因
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetDeathEnum()
        {
            List<object> idlist = new List<object>();
            foreach (var item in Enum.GetValues<DeathType>())
            {
                idlist.Add(new
                {
                    name=item.ToString(),
                    value=item,
                });
            }
            return Ok(idlist);
        }
    }
}
